package xdu.lz.stage5_jucUtils.chapter1_countdownlatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Created at 2019/10/18 0018 下午 4:29
 */
public class CDL_test4_API {

    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(1);
        Thread mainThread = Thread.currentThread();
        new Thread(()->{
            try {
                System.out.println("start");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("finish");
//            latch.countDown();
            mainThread.interrupt();
        }).start();

        try {
            latch.await(100000, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            System.out.println("latch是由main线程执行的，main线程被打断");
        }
        System.out.println("============");
    }
}
